package com.oocl.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.util.TimerTask;

import javax.xml.stream.events.StartDocument;

import com.oocl.global.GlobalVar;
import com.oocl.interaction.Browser;

public class HttpServer {
	private static Socket tsk = null;
	private static Socket hsk = null;

	public static void main(String[] args) throws InterruptedException {
		ServerSocket httpServer;
		ServerSocket tcpServer;

		try {
			httpServer = new ServerSocket(80);
			tcpServer = new ServerSocket(8888);
			
			while (true) {
				hsk = httpServer.accept();
				new Thread(new Browser(hsk)).start();
				Thread.sleep(1000);
				
				System.out.println("isOpenTcpServer: " + GlobalVar.isOpenTcpServer);
				TcpServer tcpSer = new TcpServer(tsk, tcpServer);
				if (GlobalVar.isOpenTcpServer && !GlobalVar.TcpServerStatus) {
					tcpSer.startTcpServer();
				}
				if (!GlobalVar.isOpenTcpServer && GlobalVar.TcpServerStatus) {
					tcpSer.stopTcpServer();
					System.out.println("server closed-----------");
					break;
				}

			}
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
